package de.koller.oceanFramework.math;

public class IntersectionUtil2D {

	private IntersectionUtil2D() {}
	
	public static double intersection( Vec rayA, Vec rayN, Vec l1, Vec l2 ) {
		double x1 = rayA.getX();
		double x2 = rayA.getX() + rayN.getX();
		double x3 = l1.getX();
		double x4 = l2.getX();
		double y1 = rayA.getY();
		double y2 = rayA.getY() + rayN.getY();
		double y3 = l1.getY();
		double y4 = l2.getY();
		
		double denom = (x2 - x1)*(y4 - y3) - (y2 - y1)*(x4 - x3);
		if( Math.abs( denom ) < 0.001 )
			return Double.MAX_VALUE;
		
		double a = ( (x4-x3)*(y1-y3) - (y4-y3)*(x1-x3) ) / denom;		
		return a;
	}
	
}
